<?php
/**
 *
 *
 */
namespace Yz\modules\Generic;

class Controller_List
    extends Controller_AbstractFetch
{

    const IN_MENU = true;
    const ERROR_NOT_FOUND = ':NotFound';

    protected $modelName = 'List';
    protected $model;
    protected $list;
    protected $error;


    /****************************
     *      Public methods      *
     ****************************/

    /** Custom error handler for list: handle no-items-in-list
     *
     *  @return this|false
     */
    public function doError( \Yz_Exception $ex )
    {
        if ($ex instanceof \Yz_Exception_ItemNotFound) {
            $t = $this->selectTemplate('Error');
            $t->errorMessage = $this->getErrorMessage() . self::ERROR_NOT_FOUND;
            return $this->outputTemplate($t);
        }
        return false;
    }


    /**
     *
     */
    protected function fetchData()
    {
        $this->list = $this->selectModel()->fetchList();
        return $this;
    }

    /**
     *
     */
    protected function assignTemplateParams(\Yz_Template_Interface $t)
    {
        $t->list = $this->list;
        return $this;
    }


}
